package com.lantosec.hmrp.modules.internal.controller;


import com.lantosec.hmrp.core.log.ControllerLog;
import com.lantosec.hmrp.core.log.LogType;
import org.springframework.web.bind.annotation.RequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.lantosec.hmrp.core.kit.Result;
import com.lantosec.hmrp.modules.internal.entity.InternalNote;
import com.lantosec.hmrp.modules.internal.service.IInternalNoteService;
import com.lantosec.hmrp.modules.internal.vo.InternalNoteVO;

import java.util.Arrays;
import java.util.List;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.RestController;
import com.lantosec.hmrp.core.mvc.BaseController;

/**
 *
 * 评价记录 控制器
 *
 * @author AutoCode
 * @since 2020-04-23
 */
@Api(value = "评价记录控制器", tags = "评价记录控制器")
@RestController
@RequestMapping("/internal/note")
@Log4j2
public class InternalNoteController extends BaseController {
    @Autowired
    private IInternalNoteService service;


    @PostMapping("create")
    @ControllerLog(name = "内部满意度考评提交", type = LogType.add)
    @ApiOperation(value = "内部满意度考评提交")
    public Result<Integer> taskCommit(@ApiParam(value = "评价记录VO对象", required = true) @RequestBody List<InternalNoteVO> internalNoteList){
        service.taskCommit(internalNoteList);
        return Result.ok();
    }


    @PutMapping("update")
    @ControllerLog(name = "修改内部满意度评价记录", type = LogType.update)
    @ApiOperation(value = "修改内部满意度评价记录")
    public Result<Void> update(@ApiParam(value = "评价记录VO对象", required = true) @RequestBody InternalNoteVO vo){
        InternalNote entity = vo.convertToEntity();
        service.updateById(entity);
        return Result.ok();
    }

    @DeleteMapping(value = "delete/{ids}")
    @ControllerLog(name = "逻辑删除内部满意度评价记录", type = LogType.delete)
    @ApiOperation("逻辑删除内部满意度评价记录")
    public Result<Void> delete(@ApiParam(value = "ID列表,用逗号分隔", required = true) @PathVariable(name="ids") String ids){
        if(StringUtils.isNotEmpty(ids)){
            service.removeByIds(Arrays.asList(ids.split(",")));
        }
        return Result.ok();
    }
}
